/** * Created by wust on 2020-04-02 13:06:33. */
<template>
  <el-form ref="formModel" :model="formModel" :rules="rules" label-width="120px" style="width:70%;" @submit.native.prevent>
    <el-form-item label="类型名称" prop="name"><el-input v-model="formModel.name"></el-input></el-form-item>
    <el-form-item style="text-align: left;"><el-button type="primary" @click="onSubmit('formModel')" :loading="submitting">提交</el-button></el-form-item>
  </el-form>
</template>
<script>
import Vue from 'vue';

export default {
  name: 'work-order-type-update',
  props: ['selectedModel'],
  data() {
    return {
      submitting: false,
      formModel: {
        id: null,
        name: null
      },
      rules: {
        name: [{ required: true, message: '请输入工单类型名称', trigger: 'blur' }]
      }
    };
  },
  created: function() {
    this.formModel = this.selectedModel;
  },
  methods: {
    onSubmit: function(formData) {
      this.$refs[formData].validate(valid => {
        if (!valid) {
        } else {
          Vue.$ajax({
            method: 'put',
            url: Vue.$workOrderServerURL + '/web/v1/WorkOrderTypeController',
            data: this.formModel
          }).then(res => {
            if (res.data.flag !== 'SUCCESS') {
              if (!Vue.$isNullOrIsBlankOrIsUndefined(res.data.message)) {
                this.$message({
                  message: res.data.message,
                  type: 'warning'
                });
              }
            } else {
              this.$message({
                message: res.data.message,
                type: 'success'
              });
            }
          });
        }
      });
    }
  }
};
</script>
